// 客户管理相关 API
import request from '@/utils/request';

import { ApiResponse, PageParams, PageResult } from '@/types/common';
import { CustomerInfo, CustomerForm } from '@/types/customer';
import { OrderInfo } from '@/types/order';

export const customerApi = {
  // 获取客户列表
  getCustomers: (params: PageParams): Promise<ApiResponse<PageResult<CustomerInfo>>> =>
    request.get('/customers', params),

  // 获取客户详情
  getCustomer: (id: string): Promise<ApiResponse<CustomerInfo>> =>
    request.get(`/customers/${id}`),

  // 创建客户
  createCustomer: (data: CustomerForm): Promise<ApiResponse<CustomerInfo>> =>
    request.post('/customers', data),

  // 更新客户
  updateCustomer: (id: string, data: Partial<CustomerForm>): Promise<ApiResponse<CustomerInfo>> =>
    request.put(`/customers/${id}`, data),

  // 删除客户
  deleteCustomer: (id: string): Promise<ApiResponse<void>> =>
    request.delete(`/customers/${id}`),

  // 更新客户状态
  updateCustomerStatus: (id: string, status: string): Promise<ApiResponse<void>> =>
    request.patch(`/customers/${id}/status`, { status }),

  // 获取客户订单历史
  getCustomerOrders: (id: string, params: PageParams): Promise<ApiResponse<PageResult<OrderInfo>>> =>
    request.get(`/customers/${id}/orders`, params),

  // 充值客户余额
  rechargeBalance: (id: string, amount: number): Promise<ApiResponse<void>> =>
    request.post(`/customers/${id}/recharge`, { amount }),
}; 